package cm.mefobe.android.telecomcost.adapter;

import java.util.ArrayList;
import cm.mefobe.android.telecomcost.entities.WeeklyThreshold;
import cm.mefobe.android.telecomcost.view.WeeklyThresholdEditView;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

public class WeeklyThresholdEditAdapter extends ArrayAdapter<WeeklyThreshold> {

	private Context _context;
	private ArrayList<WeeklyThreshold> items;

	public WeeklyThresholdEditAdapter(Context context, int textViewResourceId,
			ArrayList<WeeklyThreshold> _items) {
		super(context, textViewResourceId, _items);
		_context = context;
		items = _items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Log.i("WeeklyThresholdEditAdapter", "getting Threshold_row_view");
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) _context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(
					cm.mefobe.android.telecomcost.R.layout.weekly_threshold_edit_adapter_view,
					null);
		}
		
		
		WeeklyThresholdEditView thresholdView = null;
		WeeklyThreshold threshold = items.get(position);
		if (threshold != null) {
			thresholdView = (WeeklyThresholdEditView) v
					.findViewById(cm.mefobe.android.telecomcost.R.id.thresholdView);
			thresholdView.setWeeklyThreshold(threshold);			
		}
		
		return (View)thresholdView;		
	}
}
